package yyl.springboot.component;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class InitializeComponent {

	@Autowired
	@Qualifier("jdbcTemplate1")
	private JdbcTemplate jdbcTemplate1;

	@Autowired
	@Qualifier("jdbcTemplate2")
	private JdbcTemplate jdbcTemplate2;

	@PostConstruct
	public void initialize() {
		jdbcTemplate1.execute(""//
				+ " CREATE TABLE IF NOT EXISTS `hello1` (" //
				+ "  `id`    BIGINT(11)   NOT NULL auto_increment, "//
				+ "  `name`  VARCHAR(255) NOT NULL, "//
				+ "  `value` VARCHAR(255) NOT NULL, "//
				+ " PRIMARY KEY  (`id`) "//
				+ " )");
		jdbcTemplate2.execute(""//
				+ " CREATE TABLE hello2 (" //
				+ "  id    INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, "//
				+ "  name  VARCHAR(255), "//
				+ "  value VARCHAR(255)  "//
				+ " )");

	}
}
